/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util.BD;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Patricio
 */
public class ListadoDeBD {
    private Statement sen = null;
    private Connection con = null;
    private ResultSet rs = null;
    private String[] bds;

    public ListadoDeBD(Connection conexion){
        con = conexion;
    }

    public int getCantidadDeBasesDeDatosDelSistema(){
        int i = 0;
        try {
            sen = con.createStatement();
            rs = sen.executeQuery("select count(name) as cant from master.dbo.sysdatabases");
            if(rs.next()) {
                i = rs.getInt("cant");
            }
            bds = new String[i];

            sen.close();

            sen = con.createStatement();
            rs = sen.executeQuery("select name from master.dbo.sysdatabases");

            i=0;
            while(rs.next()){
                bds[i] = rs.getString("name");
                i++;
            }
            return bds.length;
        } catch (SQLException ex) {
            return -1;
        }
    }

    public String getBasesDeDatosDelSistema(int indice){
        return bds[indice];
    }
}
